/*
 * Copyright 2005 MH-Software-Entwicklung. All rights reserved.
 * Use is subject to license terms.
 */
package com.jtattoo.plaf;

import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;

/**
 * @author Michael Hagen
 */
public class BasePanelUI extends BasicPanelUI {

	private static BasePanelUI panelUI = null;

	public static ComponentUI createUI(JComponent c) {
		if (panelUI == null) {
			panelUI = new BasePanelUI();
		}
		return panelUI;
	}

	protected void installDefaults(JPanel p) {
		super.installDefaults(p);
		p.setFont(AbstractLookAndFeel.getTheme().getControlTextFont());
	}

	public void update(Graphics g, JComponent c) {
		if (c.isOpaque()) {
			if (c.getBackground() instanceof ColorUIResource) {
				g.setColor(AbstractLookAndFeel.getBackgroundColor());
			} else {
				g.setColor(c.getBackground());
			}
			g.fillRect(0, 0, c.getWidth(), c.getHeight());
		}
	}

	public void paint(Graphics g, JComponent c) {
		Graphics2D g2D = (Graphics2D) g;
		Object savedRenderingHint = null;
		if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
			savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
			g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
		}
		super.paint(g, c);
		if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
			g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
		}
	}
}
